<template>
    <div class="bgzc bgpm">
        <div class="tjzctitle">
            <img class="hzlogo" src="../assets/img/hzlogo.png" alt="">
            <span class="biaoy">用智慧，赢人生</span>
        </div>
        <div class="body1">
            <div class="biaoyuzh1">欢迎注册</div>
            <div class="tishiti"><span v-show="zctShow">提示：{{ zctishi }}</span></div>
            <div class="boxint1">
                <div class="img1"><img class="imgic1" src="../assets/img/zhanghao.png" alt=""></div>
                <div class="val1"><input class="inptzc1" type="text" placeholder='请输入手机号码' v-model="zcform.mobile"></div>
            </div>
            <div class="boxint1">
                <div class="img1"><img class="imgic1" src="../assets/img/yanzhenm.png" alt=""></div>
                <div class="val1"><input class="inptzc1" type="text" placeholder='请输入验证码'  v-model="zcform.code"></div>
                <span class="yzm1"><button class="yzmb1" :class="{disable: zcform.mobile.length !== 11}" :disabled="zcform.mobile.length !== 11" @click="huoquyzm(),getCode()" v-show="show">获取验证码</button></span>
                <span class="yzm1"><button class="yzmb1" v-show="!show">{{ count }}</button></span>
            </div>
            <div class="boxint1">
                <div class="img1"><img class="imgic1" src="../assets/img/suo.png" alt=""></div>
                <div class="val1"><input class="inptzc1" type="password" placeholder='请输入新密码' v-model="zcform.password"></div>
            </div>
            <!-- <div class="mima">找回密码</div> -->
            <div class="zcbtn1 pointer" @click="zhuceform">注册</div>
             <!-- <div class="tishi" style="font-size:3px;color:#fff;">提示：密码长度12~30位，不能以"/"开头，至少包含三项（1.小写字母a~z,2.大写字母A~z,数字0~9），不包括用户名</div> -->
        </div>
    </div>
</template>
<script>
export default {
  data () {
    return {
        show: true,
        count: '',
        timer: null,
        zctShow:false,
        zctishi:'',
        href:'',
        zcform: {
            mobile:'',
            updateType:'0',
            code:'',
            password:'',
            parentId:''
          }
    }
  },
  created() {
    console.log('打印url地址')
    console.log(window.location.href)
    this.href = window.location.href
    this.zcform.parentId = this.href.split("?")[1]
    console.log(this.zcform.parentId)

  },
  mounted() {
    
  },
  methods: {
      async huoquyzm() {
        var hqyzm = new FormData()
        hqyzm.set('mobile',this.zcform.mobile)
        hqyzm.set('updateType',this.zcform.updateType)
        const { data: res } = await this.$http.post('/app/user/sendVercode.do',hqyzm)
        console.log(res)
        if (res.code !== 0) return console.log('获取验证码失败')
        console.log('获取验证码成功')
    },
    async zhuceform() {
        var zc = new FormData()
        zc.set('mobile',this.zcform.mobile)
        zc.set('code',this.zcform.code)
        zc.set('password',this.zcform.password)
        zc.set('parentId',this.zcform.parentId)
        // const data = await this.$http.post('/app/user/sendVercode.do',`mobile=${this.zcform.mobile}&updateType=${this.zcform.updateType}`)
        const { data: res } = await this.$http.post('app/user/registerUser.do',zc)
        console.log(res)
        if (res.code !== 0){
            this.zctShow = true
          this.zctishi = res.msg
          var _that = this
          setTimeout(function(){
            _that.zctShow =false
          },3000);
        }else {
          this.zctShow = true
          this.zctishi = res.msg
          var that = this
          setTimeout(function(){
            that.zctShow =false
          },3000);
            console.log('注册成功')
            this.$router.push({
        name:'home',
        query: {
          sutankuang: true,
          msg:'注册成功，请登录'
        }
      })
        }
    },
    getCode(){
     const TIME_COUNT = 60;
     if (!this.timer) {
       this.count = TIME_COUNT;
       this.show = false;
       this.timer = setInterval(() => {
       if (this.count > 0 && this.count <= TIME_COUNT) {
         this.count--;
        } else {
         this.show = true;
         clearInterval(this.timer);
         this.timer = null;
        }
       }, 1000)
      }
   } 
  }
  }
</script>
<style lang="less" scoped>
@import "../assets/css/index.css";
::-webkit-input-placeholder{/* WebKit, Blink, Edge */color:#fff;}

:-moz-placeholder{/* Mozilla Firefox 4 to 18 */color:#fff;}

::-moz-placeholder{/* Mozilla Firefox 19+ */   color:#fff;}

:-ms-input-placeholder{/* Internet Explorer 10-11 */   color:#fff;}
    .bgzc {
        background-image: url(../assets/img/bgzc.png);
        .tjzctitle {
            position: relative;
            height: 80px;
            width: 100%;
            margin-top: 40px;
            .hzlogo {
                position: absolute;
                left: 60px;
                width: 80px;
                height: 80px;
            }
            .biaoy {
                position: absolute;
                left: 160px;
                height: 80px;
                line-height: 80px;
                color: #FFDB7E;
                font-size: 50px;
                font-weight: bold;
            }
        }
    }
    .body1 {
    margin: 170px auto;
      width: 500px;
      height: 410px;
      padding-left: 120px;
  }
    .biaoyuzh1 {
        color: #fff;
      font-size: 30px;
      font-weight: bold;
  }
    .boxint1 {
      position: relative;
      height: 40px;
      width: 360px;
      background-color: #ccc;
      background:rgba(0,0,0,.5);
      margin-top: 25px;
  }
    .img1 {
      position: absolute;
      width: 40px;
      height: 40px;
      line-height: 40px;
      top: 7px;
      left: 20px;
  }
  .imgic1 {
      width: 20px;
      height: 25px;
  }
  .val1 {
      position: absolute;
      left: 60px;
      height: 40px;
      line-height: 40px;
      color: #fff;
  }
    .inptzc1 {
      height: 32px;
      background-color: #ccc;
      background:rgba(0,0,0,.1);
      color: #fff;
      border: 0;
      outline: none;
  }
  .zcbtn1 {
      margin-top: 20px;
      height: 40px;
      width: 360px;
      background-color: #FF8B19;
      line-height: 40px;
      text-align:center;
      color: #fff;
      border-radius: 25px;
  }
  .tishi {
      width: 360px;
      height: 20px;
      margin-top: 20px;
  }
    .yzm1 {
      position: absolute;
      line-height: 40px;
      right: 20px;
  }
  .yzmb1 {
      height: 40px;
      border: 0;
      background:rgba(0,0,0,.1);
      color: #fff;
  }

</style>